//
//  WZProcedureCell.m
//  ETong
//
//  Created by wanzhao on 15/12/9.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZProcedureCell.h"

@interface WZProcedureCell ()

@property (nonatomic, weak) UILabel *biaotiLabel;
@property (nonatomic, weak) UIView *line;
@property (nonatomic, weak) UIButton *statuBtn;
@property (nonatomic, weak) UIButton *editBtn;
@property (nonatomic, weak) UIView *neirongView;


@end

@implementation WZProcedureCell

+ (WZProcedureCell *)procedureCellWithTableView:(UITableView *)tableView
{
    static NSString *procedureCellId = @"procedureCellId";
    WZProcedureCell *cell = [tableView dequeueReusableCellWithIdentifier:procedureCellId];
    if (cell == nil) {
        cell = [[WZProcedureCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:procedureCellId];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = ClearColor;
        self.backgroundColor = ClearColor;
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = ClearColor;
        label.font = Font12;
        label.textAlignment = UITextAlignmentLeft;
        label.textColor = RGBCOLORWITH16COLOR(0x333333);
        [self.contentView addSubview:label];
        self.biaotiLabel = label;

        UIView *shortLine = [[UIView alloc] init];
        shortLine.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
        [self.contentView addSubview:shortLine];
        self.line = shortLine;
        
        UIButton *statuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        statuBtn.hidden = YES;
        statuBtn.userInteractionEnabled = NO;
        [self.contentView addSubview:statuBtn];
        self.statuBtn = statuBtn;
        
        
    }
    return self;
}

- (void)setProcedureDetail:(WZProcedureDetail *)procedureDetail
{
    
    _procedureDetail = procedureDetail;
    self.biaotiLabel.text = procedureDetail.name;
    if ([procedureDetail.runStatus isEqualToString:@"运行中"]) {
        
        [self.statuBtn setImage:[UIImage imageNamed:@"yuxingzhong"] forState:UIControlStateNormal];
        self.statuBtn.hidden = NO;
        
    } else if ([procedureDetail.runStatus isEqualToString:@"异常终止"] || [procedureDetail.runStatus isEqualToString:@"异常结束"]) {
        
        [self.statuBtn setImage:[UIImage imageNamed:@"yichangzhongzhi"] forState:UIControlStateNormal];
        self.statuBtn.hidden = NO;
        
    } else if ([procedureDetail.runStatus isEqualToString:@"已结束"]) {
        
        [self.statuBtn setImage:[UIImage imageNamed:@"yijiesu"] forState:UIControlStateNormal];
        self.statuBtn.hidden = NO;
        
    } else if ([procedureDetail.runStatus isEqualToString:@"已接收"]) {
        
        [self.statuBtn setImage:[UIImage imageNamed:@"yijieshou"] forState:UIControlStateNormal];
        self.statuBtn.hidden = NO;
        
    } else if ([procedureDetail.runStatus isEqualToString:@"已停用"]) {
        
        [self.statuBtn setImage:[UIImage imageNamed:@"yitingyong"] forState:UIControlStateNormal];
        self.statuBtn.hidden = NO;
        
    } else if ([procedureDetail.runStatus isEqualToString:@"已暂停"]) {
        
        [self.statuBtn setImage:[UIImage imageNamed:@"yizanting"] forState:UIControlStateNormal];
        self.statuBtn.hidden = NO;
        
    } else {
        
        self.statuBtn.hidden = YES;
        
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.statuBtn.frame = CGRectMake(self.width - OppositeWidthRate(15) - 20.0f, 0, 20.0f, self.height);
    self.biaotiLabel.frame = CGRectMake(OppositeWidthRate(15), 0, self.statuBtn.x - OppositeWidthRate(30), self.height);
    self.line.frame = CGRectMake(OppositeWidthRate(15), self.height - 0.5f, self.width - OppositeWidthRate(15), 0.5f);
    self.editBtn.frame = CGRectMake(self.width - 60, 0, 60, self.height);
}
@end
